/** 
 
*/
import React, { PureComponent } from 'react';
import { PrimaryC, ModalC, SelectC, AdvancedSearch, FirstHeaderC, TenantC } from '@/src/comps';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { message, Modal } from 'antd';
import { connect } from 'dva';
import moment from 'moment';
import 'moment/locale/zh-cn';

const FormItemLayout = {
  labelCol: {
    xs: { span: 2, offset: 0 },
    sm: { span: 4, offset: 0 },
    md: { span: 4, offset: 0 },
    lg: { span: 4, offset: 0 },
    xl: { span: 3, offset: 0 },
    xxl: { span: 3, offset: 0 },
  },
  wrapperCol: {
    xs: { span: 22, offset: 0 },
    sm: { span: 20, offset: 0 },
    md: { span: 20, offset: 0 },
    lg: { span: 20, offset: 0 },
    xl: { span: 21, offset: 0 },
    xxl: { span: 21, offset: 0 },
  },
};

class sppiJudgmentBasis extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      bond: 1,
      loading: false,
      superMan: localStorage.getItem('antd-pro-superMan') == 'true',
    };
  }

  componentDidMount() {
    this.queryConf(this.state.superMan ? { tenantId: this.props.tenantId } : {});
    // this.props.form.resetFields()
  }

  queryConf = (payload) => {
    this.setState({
      loading: true,
    });
    this.props.dispatch({
      type: 'sppiTestRecordM/queryConf',
      payload: payload,
      callback: (res) => {
        if (res != 'fail') {
          this.setState({ bond: res?.data?.bond });
          this.props.form.setFieldsValue({ bond: res?.data?.bond || '1' });
          this.setState({
            loading: false,
          });
        }
      },
    });
  };

  onTenantChange = (e) => {
    this.queryConf({ tenantId: e.key });
  };

  render() {
    const { tenantId, form } = this.props;

    return (
      <>
        {this.state.superMan && <TenantC form={form} dataIndex='tenantId' width={220} initialValue={tenantId} onChange={(e) => this.onTenantChange(e)} allowClear={false} />}
        <SelectC
          form={form}
          // formItemLayout={FormItemLayout}
          dataIndex={'bond'}
          title='债券'
          selectWidth={220}
          onChange={(e) => this.setState({ bond: e })}
          loading={this.state.loading}
          initialValue={this.state.bond || '1'}
          dataSource={[
            { value: '1', title: '人工判断' },
            { value: '2', title: '中债判断' },
            { value: '3', title: '中证判断' },
          ]}
        />
        <SelectC
          form={form}
          // formItemLayout={FormItemLayout}
          dataIndex={'nonstandard'}
          title='非标'
          selectWidth={220}
          initialValue={'1'}
          disabled
          dataSource={[{ value: '1', title: '人工判断' }]}
        />
        <SelectC
          form={form}
          // formItemLayout={FormItemLayout}
          dataIndex={'finaFlocking'}
          title='理财直融'
          selectWidth={220}
          initialValue={'1'}
          disabled
          dataSource={[{ value: '1', title: '人工判断' }]}
        />
      </>
    );
  }
}
export default connect(({ sppiTestRecordM, loading }) => ({
  sppiTestRecordM,
  loading,
}))(sppiJudgmentBasis);
